home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 1
/
Atari Mega Archive - Volume 1.iso
/
mint
/
lib
/
mntlib44.zoo
/
mntlib
/
symlink.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-10-20
|
1KB
|
80 lines
/* soft link routines */
#include <mintbind.h>
#include <errno.h>
#include <string.h>
#include <limits.h>
#include <unistd.h>
#include <stat.h>
#include "lib.h"
extern int __mint;
/*
* If MiNT 0.9 or later is active, use the kernel routines for these;
* otherwise, try to choose failure modes that applications will best be
* able to handle
*/
int
symlink(old, new)
const char *old, *new;
{
char linkname[PATH_MAX];
char path[PATH_MAX];
long r;
if (__mint >= 9) {
_unx2dos(old, path);
_unx2dos(new, linkname);
r = Fsymlink(path, linkname);
if (r) {
errno = (int) -r;
return -1;
}
return (int) r;
}
errno = EINVAL;
return -1;
}
int
readlink(unxname, buf, siz)
char *unxname, *buf;
int siz;
{
long r;
size_t l;
char filename[PATH_MAX];
char linkto[PATH_MAX+1];
if (__mint < 9) {
errno = EINVAL;
return -1;
}
_unx2dos(unxname, filename);
r = Freadlink(PATH_MAX, linkto, filename);
if (r < 0) {
if (r == -EACCES) {
struct stat sb;
/* UNIX gives EINVAL, not EACCES, on non-links */
if ((Fxattr(1, filename, &sb) == 0)
&& ((sb.st_mode & S_IFMT) != S_IFLNK)) {
r = -EINVAL;
}
}
errno = (int) -r;
return -1;
}
linkto[PATH_MAX] = 0;
_dos2unx(linkto, filename);
l = strlen(filename);
if (l > siz) {
errno = ERANGE;
return -1;
}
strncpy(buf, filename, siz);
return (int) l;
}